<style type="text/css">
    .wangEditor-container .content{
        min-height: auto;
    }
</style>
<section class="content-header">
    <h1>
        文章管理
        <small></small>
    </h1>
</section>

<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <!-- general form elements -->
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">新增文章</h3>
                </div>
                <!-- form start -->
                <form class="form-horizontal" action="/admin/article/add" method="post" enctype="text/plain">
                    <div class="box-body">
                        <input class="form-control" name="id" placeholder="" value="{{article.id}}"
                               type="hidden">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">标题</label>

                            <div class="col-sm-10">
                                <input class="form-control" name="title" placeholder="" value="{{article.title}}"
                                       type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">作者</label>

                            <div class="col-sm-10">
                                <input class="form-control" name="author" placeholder="" value="{{article.author}}"
                                       type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">简介</label>

                            <div class="col-sm-10">
                                <textarea class="form-control" name="sub"
                                          rows="3">{{article.sub}}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2"></label>

                            <div class="col-sm-10">
                                <div style="color: #dd4b39">最佳尺寸：350*200px</div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">图片</label>

                            <div class="col-sm-10">
                                <div class="fileupload fileupload-new" data-provides="fileupload">
                                    <div class="fileupload-new img-thumbnail">
                                        {{#gt article.file_id 0}}
                                            <img src="/public/uploads/{{article.file.savepath}}{{article.file.savename}}">
                                        {{else}}
                                            <img src="/admin/dist/img/noimage.gif">
                                        {{/gt}}

                                        <input class="form-control" name="file_id" id="file_id" placeholder=""
                                               value="{{article.file_id}}"
                                               type="hidden">

                                        <div class="edit_pic_mask">
                                            <i class="fa fa-plus-circle" onclick="imageUploader(this,false)"></i>
                                            <i class="fa fa-minus-circle" onclick="removeImage(this,false)"></i>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序</label>

                            <div class="col-sm-10">
                                <input class="form-control" name="rank" placeholder="" value="{{article.rank}}"
                                       type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">备注</label>

                            <div class="col-sm-10">
                                <input class="form-control" name="remark" placeholder="" value="{{article.remark}}"
                                       type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-2">状态</label>

                            <div class="col-md-7">
                                <label class="radio-inline"><input name="status" type="radio"
                                                                   {{#eq article.status 1}}checked="checked" {{/eq}}
                                    value="1"><span>开启</span></label>
                                <label class="radio-inline"><input name="status" type="radio"
                                                                   {{#eq article.status 0}}checked="checked" {{/eq}}
                                    value="0"><span>关闭</span></label>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label col-md-2">类型</label>

                            <div class="col-md-7">
                                <label class="radio-inline"><input name="type" type="radio"
                                                                   {{#eq article.type 3}}checked="checked" {{/eq}}
                                    value="3"><span>电商经验谈</span></label>
                                <label class="radio-inline"><input name="type" type="radio"
                                                               {{#eq article.type 2}}checked="checked" {{/eq}}
                                value="2"><span>今日头条</span></label>
                                <label class="radio-inline"><input name="type" type="radio"
                                                                   {{#eq article.type 1}}checked="checked" {{/eq}}
                                    value="1"><span>推荐阅读</span></label>
                                <label class="radio-inline"><input name="type" type="radio"
                                                                   {{#eq article.type 0}}checked="checked" {{/eq}}
                                    value="0"><span>最新资讯</span></label>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">内容</label>

                            <div class="col-sm-10">
                                <textarea id="editor" name="content" style="height:400px;display:none">
                                    {{{article.content}}}
                                </textarea>
                            </div>
                        </div>
                    </div>

                    <div class="box-footer">
                        <div class="col-sm-2">
                            <button type="submit" class="btn btn-block btn-danger">保存</button>
                        </div>

                        <div class="col-sm-2">
                            <button type="button" class="btn btn-block btn-default" onclick="history.go(-1)">取消
                            </button>
                        </div>
                    </div>

                </form>
            </div>
            <!-- /.box -->
        </div>
        <!--/.col (right) -->
    </div>
</section>

<script type="text/javascript">
    $(document).ready(function () {

        var editorContainer = $('.wangEditor-container');
        if(!editorContainer.length){

            var editor = new wangEditor('editor');
            editor.config.menuFixed = false;
            editor.config.uploadImgUrl = '/admin/editor/add';
            editor.config.uploadImgFileName = 'file';
            editor.config.menus = $.map(wangEditor.config.menus, function(item, key) {
                if (item === 'location') {
                    return null;
                }
                return item;
            });

            editor.create();
        }
    });
</script>